<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('活动信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>活动编号：</p>
                            <input type="text" name="activityId"/>
                        </li>
                        <li>
                            <p>活动名称：</p>
                            <input type="text" name="activityName"/>
                        </li>
                        <li>
                            <p>活动类型：</p>
                            <select name="activityType" th:with="type=${@dict.getType('t_activity_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>活动属性：</p>
                            <select name="activityAttribute" th:with="type=${@dict.getType('t_activity_attribute')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>类别限制：</p>
                            <div class="input-group" style="width: 200px;">
                                <input id="treeId" name="categoryId" type="hidden"
                                       th:value="${commodityCategory?.categoryId}"/>
                                <input placeholder="点击选择类别" class="form-control" type="text"
                                       onclick="selectCommoditycategoryTree()"
                                       id="treeName"
                                       readonly="true" th:value="${commodityCategory?.categoryName}" required>
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="bussiness:activityinfo:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="bussiness:activityinfo:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('bussiness:activityinfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bussiness:activityinfo:remove')}]];
    var activityTypeDatas = [[${@dict.getType('t_activity_type')}]];
    var activityAttributeDatas = [[${@dict.getType('t_activity_attribute')}]];
    var prefix = ctx + "bussiness/activityinfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "活动信息",
            sortName: "zebraOrder asc,createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'activityId',
                    title: '活动编号'
                },
                {
                    field: 'activityName',
                    title: '活动名称'
                },
                {
                    field: 'categoryName',
                    title: '类别限制',
                    formatter: function (value) {
                        if (!value) {
                            return '不限制';
                        }
                        return value;

                    }
                },
                {
                    field: 'activityImg',
                    title: '活动图片',
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'activityInfo',
                    title: '活动信息'
                },
                {
                    field: 'activityType',
                    title: '活动类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(activityTypeDatas, value);
                    }
                },
                {
                    field: 'activityAttribute',
                    title: '活动属性',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(activityAttributeDatas, value);
                    }
                },
                {
                    field: 'zebraOrder',
                    title: '排序'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true,
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true,
                },
                {
                    field: 'updateBy',
                    title: '操作人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.activityId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.activityId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*产品类别-新增-选择父部门树*/
    function selectCommoditycategoryTree() {
        var options = {
            title: '产品类别选择',
            width: "380",
            url: ctx + "bussiness/commoditycategory/selectCommoditycategoryTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree, true)) {
            var body = layer.getChildFrame('body', index);
            var goodId = body.find('#treeId').val();
            $("#treeId").val(goodId);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>